package com.xinghanlaser.applet.base.auth.controller;

import com.xinghanlaser.applet.base.auth.query.RoleQuery;
import com.xinghanlaser.applet.base.auth.service.IRoleService;
import com.xinghanlaser.applet.base.auth.vo.RoleDataVO;
import com.xinghanlaser.applet.base.auth.vo.RolePostVO;
import com.xinghanlaser.applet.base.auth.vo.RolePutVO;
import com.xinghanlaser.applet.base.common.entity.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Set;

/**
 * <p>
 *
 * <p>
 *
 * @author: mftuo 陀铭峰
 * @since: 2024/4/30 8:57
 */
@RestController
@RequestMapping("/admin/role")
@Api(value = "角色管理", tags = "角色管理")
public class RoleController {
    @Resource
    private IRoleService service;

    @GetMapping("/page")
    @ApiOperation("根据条件分页查询角色")
    public ResponseEntity<ResponseEntity.PageResult<RoleDataVO>> pageByCondition(RoleQuery query){
        return service.pageByCondition(query);
    }

    @GetMapping("/{roleId}")
    @ApiOperation("根据ID查询角色")
    public ResponseEntity<RoleDataVO> getRoleById(@PathVariable("roleId")Long id){
        return service.getRoleById(id);
    }

    @GetMapping("/listByUserId/{userId}")
    @ApiOperation("根据用户ID查询角色")
    public ResponseEntity<Set<RoleDataVO>> getRoleListByUserId(@PathVariable("userId") Long id){
        return service.getRoleListByUserId(id);
    }

    @PostMapping
    @ApiOperation("新增角色")
    public ResponseEntity<Void> addRole(@RequestBody @Valid RolePostVO postVO){
        return service.addRole(postVO);
    }

    @PutMapping
    @ApiOperation("修改角色信息")
    public ResponseEntity<Void> modRole(@RequestBody @Valid RolePutVO putVO){
        return service.modRole(putVO);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除角色")
    public ResponseEntity<Void> delRole(@PathVariable("id")Long id){
        return service.delRole(id);
    }
}
